<?php

class HTime extends CWidget {
    
    public $name;
    //type 1: example 10:10:10 PM; type: 2 example 22:10:10
    public $type = '1';
    public $time = 0;
    
    public function init() {
        if(!$this->name) {
            $this->name = 'HTime';
        }
    }
    
    public function run() {
        parent::run();
        
        $aHours = array();
        if($this->type == 1) {
            for($i=0; $i<=23; ++$i) {
                $aHours[] = str_pad($i, 2, 0, STR_PAD_LEFT);
            }
        } else {
            for($i=0; $i<=12; ++$i) {
                $aHours[$i] = str_pad($i, 2, 0, STR_PAD_LEFT);
            }
        }
        
        $aMinutes = array();
        
        for($i=0; $i<=59; ++$i) {
            $aMinutes[$i] = str_pad($i, 2, 0, STR_PAD_LEFT);
        }
        
        $iHour = 0;
        $iMinute = 0;
        if($this->time) {
            $iHour = (int) date('H', $this->time);
            $iMinute = (int) date('i', $this->time);
            
            list($iHour, $iMinute,$iSecond) = HCTime::sencondsToTime($this->time);
        }
        $this->render('index', compact('aHours', 'aMinutes', 'iHour', 'iMinute'));
    }
    
    
}
